package 算法.leetcode.offer;

import java.util.Arrays;

/**
 * @author lchenglong
 * @date 2022/3/20
 */
public class Offer61 {

    public static void main(String[] args) {
        Offer61 instance = new Offer61();
        boolean straight = instance.isStraight(new int[]{0, 0, 2, 2, 5});
        System.out.println(straight);
    }
    public boolean isStraight(int[] nums) {
        int dif = 0;
        Arrays.sort(nums);
        for (int i=0;i<nums.length;i++){
            if (nums[i] == 0)++dif;
        }
        for (int i=1+dif;i<nums.length;i++){
            if (nums[i]-nums[i-1]>1) {
                dif -= nums[i]-nums[i-1]-1;
            } else if (nums[i] == nums[i-1])
                return false;
        }
        if (dif<0)return false;
        else return true;
    }
}
